package com.baidu.model;



import java.util.List;





import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;

/**
 * 回帖内容 
 * @author libs
 * 2015-12-23 11:46
 */
public class ReplyContent extends Model<ReplyContent>{
	
	private static final long serialVersionUID = 282908528936842633L;
	public static final ReplyContent dao = new ReplyContent();
	
	/**
	 * 根据用户Id查询回帖内容
	 * @param bdGuid
	 * @return
	 */
	public List<ReplyContent> findByUserId(String bdGuid) {
		StringBuffer hql = new StringBuffer();
		hql.append("select a.* from reply_content a");
		hql.append(" where 1=1");
		hql.append(" and a.bdGuid=?");
		return this.find(hql.toString(), bdGuid);
	}
	
	/**
	 * 从字典库中初始化20条回复内容到该百度账号
	 * @param str
	 */
	public void initReContent(String bdGuid) {
		List<DictContent> list = DictContent.dao.queryRandomByNum(20);
		List<ReplyContent> rcList= findByUserId(bdGuid);
		if(list != null && list.size() != 0 && (rcList == null || rcList.size() == 0)){
			for (DictContent dc : list) {
				ReplyContent rc = new ReplyContent();
				rc.set("content", dc.getStr("content"));
				rc.set("bdGuid", bdGuid);
				rc.save();
			}
		}
	}

    /**
     * 删除自定义回帖内容
     * @param para
     */
    public void delByBDGuid(String guid) {
        Db.update("delete from reply_content where bdGuid = ?", guid);
    }
}
